/**
 * 使用栈判断表达式的的括号是否匹配
 * 表达式中允许包含三种括号：圆括号、方括号和大括号
 * 如：(…[…{…}…[22+77]…]…(…))
 */
const Stack = require("./stackDefine");
function check(expression) {
  const stack = new Stack();
  for (let i in expression) {
    // 入栈
    if (
      expression[i] === "(" ||
      expression[i] === "{" ||
      expression[i] === "["
    ) {
      stack.push(expression[i]);
    }
    // 出栈
    if (
      expression[i] === ")" ||
      expression[i] === "}" ||
      expression[i] === "]"&&
      !stack.isEmpty()
    ) {
      stack.pop(expression[i]);
    }
  }
  if(stack.isEmpty()) return true
  else return false
}
let str = "12*15+(10+2)/5"
console.log(check(str));
